<?php

if (!$usr->checkPermission('mod_formmailer_tables','u'))
{
    print "<b>Sie haben nicht die entsprechenden Rechte, um die Tabellen einzurichten!</b>";
    exit;
}

if ($env->param('createTables')){
 if ($env->param('forms')){
   print "Erzeuge Formulare<br>";
   $udba->query("Drop table ".$tableforwarder."_formmailerField;");
   $udba->query("create table ".$tableforwarder."_formmailerField (instance varchar(40) not null, name varchar(100) not null, type int unsigned not null, value text, checking varchar(100), description varchar(255), size int, maxlength int, selected enum('N','Y') not null, pos smallint unsigned, index(instance,name));");
   $udba->query("Drop table ".$tableforwarder."_formmailerEMail;");
   $udba->query("create table ".$tableforwarder."_formmailerEMail (instance varchar(40) not null, to_email varchar(255), send_ack enum('Y','N') not null, from_email varchar(255), reply_to_email varchar(255), organization varchar(255), content_type enum('text/plain','text/html'), index(instance));");
   $udba->query("Drop table ".$tableforwarder."_formmailerTpl;");
   $udba->query("create table ".$tableforwarder."_formmailerTpl (instance varchar(40) not null, type enum('form','ack'), subject varchar(255), tpl text, index(instance));");
   $udba->query("Drop table ".$tableforwarder."_formmailerFieldTpl;");
   $udba->query("create table ".$tableforwarder."_formmailerFieldTpl (id int not null auto_increment,name varchar(255) not null unique, tpl text, primary key(id));");
   $udba->query("Drop table ".$tableforwarder."_formmailerAditional;");
   $udba->query("create table ".$tableforwarder."_formmailerAditional (instance varchar(40) not null, errormsg text, finscreen text);");

/** textarea **/
$tplstr = '<is:conf type="textarea" />
<is:separator pos="top">
</is:separator>
<is:separator pos="between">
</is:separator>
<is:separator pos="bottom">
</is:separator>
<is:formitem state="accepted">
<div class="formmailer-row formmailer-accepted">
    <span class="label">#data[description]#:</span>
    <span class="feld"> <textarea name="#data[name]#" cols="#data[size]#" rows="#data[maxlength]#">#data[formdata]#</textarea></span>
</div>
</is:formitem>
<is:formitem state="rejected">
<div class="formmailer-row formmailer-rejected">
    <span class="label"><b>#data[description]#</b>:</span>
    <span class="feld"> <textarea name="#data[name]#" cols="#data[size]#" rows="#data[maxlength]#">#data[formdata]#</textarea></span>
</div>
</is:formitem>
<is:formitem state="initial">
<div class="formmailer-row formmailer-initial">
    <span class="label">#data[description]#:</span>
    <span class="feld"> <textarea name="#data[name]#" cols="#data[size]#" rows="#data[maxlength]#">#data[value]#</textarea></span>
</div>
</is:formitem>'."\n";
$udba->query("insert into ".$udba->tableforwarder."_formmailerFieldTpl (name,tpl) values ('Textbereich','$tplstr');");
/** textfield **/
$tplstr = '<is:conf type="text" />
<is:separator pos="top">
</is:separator>
<is:separator pos="between">
</is:separator>
<is:separator pos="bottom">
</is:separator>
<is:formitem state="accepted">
<div class="formmailer-row formmailer-accepted">
    <span class="label">#data[description]#:</span>
    <span class="feld"> <input type="text" name="#data[name]#" value="#data[formdata]#" size="#data[size]#" maxlength="#data[maxlength]#" /></span>
</div>
</is:formitem>
<is:formitem state="rejected">
<div class="formmailer-row formmailer-rejected">
    <span class="label"><b>#data[description]#</b>:</span>
    <span class="feld"> <input type="text" name="#data[name]#" value="#data[formdata]#" size="#data[size]#" maxlength="#data[maxlength]#" /></span>
</div>
</is:formitem>
<is:formitem state="initial">
<div class="formmailer-row formmailer-initial">
    <span class="label">#data[description]#:</span>
    <span class="feld"> <input type="text" name="#data[name]#" value="#data[value]#" size="#data[size]#" maxlength="#data[maxlength]#" /></span>
</div>
</is:formitem>'."\n";
$udba->query("insert into ".$udba->tableforwarder."_formmailerFieldTpl (name,tpl) values ('Textfeld','$tplstr');");
/** select **/
$tplstr = '<is:conf type="select" />
<is:separator pos="top">
</is:separator>
<is:separator pos="between">
</is:separator>
<is:separator pos="bottom">
</is:separator>
<is:formitem state="accepted">
<div class="formmailer-row formmailer-accepted">
    <span class="label">#data[description]#:</span>
    <span class="feld"> <select name="#data[name]#">#data[formdata]#</select></span>
</div>
</is:formitem>
<is:formitem state="rejected">
<div class="formmailer-row formmailer-rejected">
    <span class="label"><b>#data[description]#</b>:</span>
    <span class="feld"> <select name="#data[name]#">#data[formdata]#</select></span>
</div>
</is:formitem>
<is:formitem state="initial">
<div class="formmailer-row formmailer-initial">
    <span class="label">#data[description]#:</span>
    <span class="feld"> <select name="#data[name]#">#data[value]#</select></span>
</div>
</is:formitem>'."\n";
$udba->query("insert into ".$udba->tableforwarder."_formmailerFieldTpl (name,tpl) values ('Auswahlfeld','$tplstr');");
/** checkbox **/
$tplstr = '<is:conf type="checkbox" />
<is:separator pos="top">
</is:separator>
<is:separator pos="between">
</is:separator>
<is:separator pos="bottom">
</is:separator>
<is:formitem state="accepted">
<div class="formmailer-row formmailer-accepted">
    <span class="label">#data[description]#:</span>
    <span class="feld"> <input type="checkbox" name="#data[name]#" value="#data[value]#" #data[formdata]#  /></span>
</div>
</is:formitem>
<is:formitem state="rejected">
<div class="formmailer-row formmailer-rejected">
    <span class="label"><b>#data[description]#</b>:</span>
    <span class="feld"> <input type="checkbox" name="#data[name]#" value="#data[value]#" #data[formdata]#  /></span>
</div>
</is:formitem>
<is:formitem state="initial">
<div class="formmailer-row formmailer-initial">
    <span class="label">#data[description]#:</span>
    <span class="feld"> <input type="checkbox" name="#data[name]#" value="#data[value]#" #data[selected]#  /></span>
</div>
</is:formitem>'."\n";
$udba->query("insert into ".$udba->tableforwarder."_formmailerFieldTpl (name,tpl) values ('Checkbox','$tplstr');");
/** radiogroup **/
$tplstr = '<is:conf type="radiogroup" />
<is:separator pos="top">
#data[descr]#
</is:separator>
<is:separator pos="between">
#data[descr]#
</is:separator>
<is:separator pos="bottom">
#data[descr]#
</is:separator>
<is:formitem state="accepted">
<div class="formmailer-row formmailer-accepted">
    <span class="label">#data[value]#:</span>
    <span class="feld"> <input type="radio" name="#data[name]#" value="#data[value]#" #data[formdata]#  /></span>
</div>
</is:formitem>
<is:formitem state="rejected">
<div class="formmailer-row formmailer-rejected">
    <span class="label"><b>#data[value]#</b>:</span>
    <span class="feld"> <input type="radio" name="#data[name]#" value="#data[value]#" #data[formdata]#  /></span>
</div>
</is:formitem>
<is:formitem state="initial">
<div class="formmailer-row formmailer-initial">
    <span class="label">#data[value]#:</span>
    <span class="feld"> <input type="radio" name="#data[name]#" value="#data[value]#" #data[selected]#  /></span>
</div>
</is:formitem>'."\n";
$udba->query("insert into ".$udba->tableforwarder."_formmailerFieldTpl (name,tpl) values ('Radiogruppe','$tplstr');");

 }
} else {
?>
<?php echo $udba->getError() ?>
<form action="<?=$formmailer?>" method="GET">
                <input type="hidden" name="module" value="<?=$module?>">
                <input type="hidden" name="instance" value="<?=$instance?>">
                <input type="hidden" name="target" value="createTables.php">
                <input type="hidden" name="createTables" value="true">
		<input type="checkbox" value="on" name="forms"> Formulare <br>
		<input type="submit" class="button" value="einrichten">
</form>
<?php
}
?>
